import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Student } from '../../student/entities/student.entity';
import { LessonsSort } from '../../lessons-sort/entities/lessons-sort.entity';

/**
 * 学生选课表
 */
@Entity()
export class StudentCourse {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ comment: '学生id', nullable: true })
  student_id: number;
  @ManyToOne(() => Student, (student) => student.studentCourse, {
    onDelete: 'SET NULL',
    cascade: ['insert', 'update'],
  })
  @JoinColumn({
    name: 'student_id',
  })
  student: Student;

  @ManyToMany(() => LessonsSort, (lessonsSort) => lessonsSort.studentCourse, {
    onDelete: 'CASCADE',
    cascade: true,
  })
  @JoinTable({
    name: 'studentCourse_lessonsSort',
  })
  lessonsSorts: LessonsSort[];
}
